﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Common.Linq;

namespace CoreEx.Database.Linq.Implementation
{
    public class SampleExpressionVisitor : ExpressionVisitor
    {
        private static Expression StripQuotes(Expression e)
        {

            while (e.NodeType == ExpressionType.Quote)
            {

                e = ((UnaryExpression)e).Operand;

            }

            return e;

        }
        
        protected override System.Linq.Expressions.Expression VisitMethodCall(System.Linq.Expressions.MethodCallExpression m)
        {
            if (m.Method.Name == "Select" && m.Method.DeclaringType == typeof(Queryable))
            {
                LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                Console.WriteLine("");
            }
            
            return base.VisitMethodCall(m);
        }
        
        public void Translate(Expression expression)
        {
            this.Visit(expression);
        }

    }
}
